library ItemType requires Table, Property

    struct ItemType
        implement Property

        //名称
        string m_name
        //物品ID
        integer m_itemId
        //装备类型
        integer m_equipTypeId
        //金币价格
        integer m_cost
        //物品描述
        string m_desc
        //物品额外描述
        string m_exDesc
        //图标路径
        string m_icon

        private static Table cache

        private method reset takes nothing returns nothing
            set m_name = ""
            set m_itemId = 0
            set m_equipTypeId = 0
            set m_cost = 0
            set m_desc = ""
            set m_exDesc = ""
            set m_icon = ""
        endmethod

        static method create takes integer itemId returns thistype
            local thistype this = thistype(cache[itemId])
            if this > 0 then
                return this
            endif
            set this = thistype.allocate()
            call this.reset()

            set this.m_itemId = itemId
            set cache[itemId] = this
            return this
        endmethod

        method destroy takes nothing returns nothing
            call cache.remove(m_itemId)

            call this.reset()
            call this.deallocate()
        endmethod

        private static method onInit takes nothing returns nothing
            set cache = Table.create()
        endmethod
        
    endstruct

endlibrary